<template>
	<view class="container">
		<view class="search_box">
			<view class="search_input_box">
				<u--input placeholder="请输入内容" border="none" prefixIcon="search"
					prefixIconStyle="font-size: 22px;color: #909399"></u--input>
			</view>
		</view>
		<view class="goods_list_box">
			<view class="goods_item_box" v-for="(item,index) in goodsData" :key="item.productId" @click="toGoodsDetail(item)">
				<view class="goods_img_box">
					<image :src="item.sliderImage" class="goods_img" mode="widthFix"></image>
				</view>

				<view class="goods_title_box">
					<text class="color_commodity">
						{{item.colorOfCommodityName}}
					</text>
					<text class="goods_name">
						{{item.name}}-{{item.name}}
					</text>
				</view>
				<view class="tag_box">
					<text class="tag_item" v-for="(item1,index1) in item.commodityTag" :key="index1">
						{{item1}}
					</text>
				</view>
				<view class="price_box">
					<text class="price_symbol">￥</text>
					<text class="price_num">{{item.dailyRent}}</text>
					<text class="price_day">/起</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let app = getApp();
	import {
		getProductListApi
	} from '@/api/product.js'
	export default {
		data() {
			return {
				cate_id: '',
				cate_name: '',
				searchParams: {
					limit: 10,
					page: 1,
					categoryId: '',
					productName: ''
				},
				goodsData: []
			}
		},
		onLoad(query) {
			let that = this;
			that.cate_id = query.cate_id;
			that.searchParams.categoryId = query.cate_id;
			that.cate_name = query.cate_name;
			that.getGoodsList()
		},
		methods: {
			getGoodsList() {
				let that = this;
				getProductListApi(that.searchParams).then(res => {
					if (res.code == '200') {
						that.goodsData = res.data.list
						that.goodsData.forEach(item => {
							item.commodityTag = item.commodityTag.split(';')
						})
						console.log('that.goodsData', that.goodsData);
					} else {
						uni.showToast({
							icon: 'fail',
							title: res.message
						})
					}
				})
			},
			toGoodsDetail(item) {
				let that = this;
				uni.navigateTo({
					url: '/pages/goods/goods_details/index?id=' + item.productId + '&merId=' + item.merId
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		background: #F6F6F6;

		.search_box {
			box-sizing: border-box;
			width: 100%;
			height: 100%;
			padding: 24rpx;
			background-color: #fff;

			.search_input_box {
				box-sizing: border-box;
				width: 100%;
				height: 64rpx;
				padding: 0 24rpx;
				background-color: #fff;
				border-radius: 32rpx;
				border: 2rpx solid rgba(255, 102, 0, 0.45);
				overflow: hidden;

				/deep/.u-input {
					height: 64rpx !important;
				}
			}
		}

		.goods_list_box {
			box-sizing: border-box;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 24rpx;

			.goods_item_box {
				box-sizing: border-box;
				width: 47%;
				background-color: #fff;
				border-radius: 24rpx;
				overflow: hidden;
				padding: 16rpx;

				.goods_img_box {
					width: 100%;
					height: 300rpx;

					.goods_img {
						width: 100%;
					}
				}

				.goods_title_box {
					box-sizing: border-box;
					width: 100%;
					// height: 110rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
					line-height: 40rpx;
					margin-top: 16rpx;

					.color_commodity {
						background: linear-gradient(270deg, #FF3B3B 0%, #FF6E13 100%);
						border-radius: 12rpx 8rpx 12rpx 0rpx;
						font-weight: 400;
						font-size: 20rpx;
						color: #FFFFFF;
						text-align: center;
						margin-right: 8rpx;
						padding: 0 8rpx;
					}

					.goods_name {
						font-weight: 500;
						font-size: 28rpx;
						color: rgba(0, 0, 0, 0.85);
					}
				}

				.tag_box {
					width: 100%;
					margin-top: 16rpx;

					.tag_item {
						background: rgba(251, 92, 88, 0.1);
						padding: 0 5rpx;
						border-radius: 8rpx;
						font-weight: 400;
						font-size: 20rpx;
						color: #FC5953;
						line-height: 28rpx;
						margin-right: 14rpx;
					}

					.tag_item:last-child {
						margin-right: 0;
					}
				}

				.price_box {
					color: #F9220E;
					line-height: 40rpx;
					margin-top: 16rpx;

					.price_symbol,
					.price_day {
						font-size: 24rpx;
					}

					.price_num {
						font-size: 36rpx;
						margin-left: 5rpx;
					}
				}
			}
		}
	}
</style>